<template>
  <div class='v-wel' :style='{width:width+"px",height: height-350+"px"}'>
    <article class='w-per-100 h-per-100 p-f-xl-yt p-t-100 o-a f-s-c f-column' :style='{height: height-300+"px"}'>
      <div class='b-r-14 w-per-90 p-lr-30 p-tb-20'>
      <el-collapse v-model="activeName" accordion >
        <el-collapse-item
          v-for='(item,index) in list' 
          :title="item.title" 
          :name='index'
          :key='item.title'
        >
          <div class='f-b-c'>
            <section v-for='unit in item.children' :key='unit.title'>
              <el-link v-if='!!unit.path' :href='"#"+unit.path' type="primary" class='f-s-20'>{{unit.title}}</el-link>
              <div v-else>
                <h3 class='f-s-22 f-w-600'>{{unit.title}}</h3>
                <section v-for='link in unit.children' :key='link.title'>
                  <el-link v-if='!!link.path' :href='"#"+link.path' type="primary" class='f-s-20'>{{link.title}}</el-link>
                </section>
              </div>
            </section>
          </div>
        </el-collapse-item>
      </el-collapse>
      </div>
    </article>
  </div>

</template>

<script>
  import {projectRegister, projectList} from "@/api/planning/project";
  import {resultHotWord} from "@/api/planning/result";
  import {listTask} from "@/api/planning/detailList";
  import {getTopicPage, rollData} from "@/api/planning/message";
  import {mapGetters} from "vuex";
  import {getunreadMsg} from "@/api/system";
  import {toDoList, toDoTargetOpinion, toDoReviewList} from "@/api/review";
  import {getLevyFeedbackSingleList, getEndSubjectList} from "@/api/subject";
  import {getTodoList} from "@/api/fileTask";
  import {opinionTagertList} from "@/api/opinion"
  import messageScroll from '@/components/currency/messageScroll'
  import {toDoReportList, taskTodo, decomposeDraftProgressTree} from "@/api/pim/pim";


  export default {
    name: "wel",
    data() {
      return {
        activeName:0,
        width: window.innerWidth,
        height: window.innerHeight,
        rollMessageData: [],
        publicPath: process.env.BASE_URL,
        realTime: '',//当前时间
        searchInput: '',//搜索框信息
        dialogVisible: false,
        chooseFlag: 'A',
        scheduleTotal: 0,//待办规划数量
        listTotal: 0,//待办清单数量
        topicTotal: 0,//会商反馈数量
        reviewTotal: 0,//待办审批数量
        unreadMsgTotal: 0,//通知消息数量
        opinionTotal: 0,//意见反馈数量
        subjectTotal: 0,//课题征集数量
        collectionTotal: 0,//材料收集数量
        opinionTagertTotal: 0,//规划衔接数量
        endSubjectTotal: 0,//结题申请数量
        reportTotal: 0,//监测评估数量
        adjustTotal: 0,//修订调整数量
        workitemTotal: 0,//进度上报数量
        fgwJudgeView: false,
        dialogWidthParam: '1000px',

        list1: {
          title: '目录清单管理',
          children: [
            {
              title: '空间规划',
              path: '/applyFor/index?chooseFlag=D'
            },
            {
              title: '专项规划',
              path: '/applyFor/index?chooseFlag=B'
            },
            {
              title: '区域规划',
              path: '/applyFor/index?chooseFlag=C'
            },
            
            {
              title: '结果查询',
              path: '/listConlumn/index'
            }
          ]
        },
        list2: {
          title: '规划实时跟踪',
          children: [
            {
              title: '责任分解',
              path: '/pim/model/index'
            },
            {
              title: '监测评估',
              path: '/pim/monitor/index'
            },
            {
              title: '修订调整',
              path: '/adjustment/detail'
            },
          ]
        },
        list3: {
          title: '规划成果管理',
          children: [
            {
              title: '成果录入',
              path: '/resultAdd/index'
            },
            {
              title: '成果查询',
              path: '/listFeedback/detail/cgrk'
            },
            {
              title: '成果统计',
              path: '/projectChart/index'
            },
          ]
        },
        list4: {
          title: '规划流程管理',
          children: [
            {
              title: '前期研究',
              children: [
                {
                  title: '课题计划',
                  path: '/subjectPlanList/index'
                },
                {
                  title: '课题研究',
                  path: '/subjectReportList/index'
                },
                {
                  title: '课题成果',
                  path: '/subjectRelease/index'
                },
              ]
            },
            {
              title: '规划编制',
              children: [
                {
                  title: '起草文案',
                  path: '/planningPlait/detail?type=起草文稿'
                },
                {
                  title: '征求意见',
                  path: '/planningPlait/detail?type=征求意见'
                },
                {
                  title: '论证评审',
                  path: '/argumentReview/index'
                }
              ]
            },
            {
              title: '审批发布',
              children: [
                {
                  title: '规划衔接',
                  path: '/planningConnection/index'
                },
                {
                  title: '规划审批',
                  path: '/planningReleaseList/detail'
                },
                {
                  title: '成果发布',
                  path: '/resultReleaseList/index'
                }
              ]
            },
          ]
        },
        list5: {
          title: '我的工作',
          children: [
            {
              title: '待办任务',
              path: '/toDo/index'
            },
            {
              title: '已办任务',
              path: '/finished/index'
            },
            {
              title: '任务跟踪',
              path: '/application/index'
            }
          ]
        }
      };
    },
    mounted() {
      this.getScheduleList();
      this.getTaskList();
      this.getTopicList();
      this.getReviewList();
      this.hotSearch();
      this.realTime = this.dealWithTime();
      this.getUnreadTotal();
      this.getToDoList();
      this.getResultList();
      this.getmaterialCollectionSingle();
      this.getopinionTagertList();
      this.getendSubjectTotal();
      this.getReportTotalTotal();
      this.getAdjustTotal();
      this.decomposeDraftProgressTree();
      this.rollData()
    },
    computed: {
      ...mapGetters([
        "userInfo",
        "permissions",
        "roles"
      ]),
      list() {
        try {
          if (this.permissions.planning_list_kjgh || this.permissions.planning_list_zxqy) {
            this.list1.children.push({
                title: '清单报价',
                path: '/protocol/index'
            })
          }
        } catch (error) {
          console.warn(error)
        }

        return [
          this.list1,
          this.list2,
          this.list3,
          this.list4,
          this.list5,
        ]
      }
    },
    filters: {
      // 不显示0
      notZero: function (value) {
        if (value == 0) {
          return ''
        }
        return value
      }
    },
    watch: {
      searchInput: function (val) {
        this.hotSearch(val);
      }
    },
    methods: {
      rollData() {
        rollData().then(response => {
          if (response.data.code == 0) {
            this.rollMessageData = response.data.data;
          }
        })
      },
      getToDoTotal() {
        let total = this.scheduleTotal + this.listTotal + this.topicTotal + this.reviewTotal + this.workitemTotal + this.opinionTotal + this.opinionTagertTotal + this.endSubjectTotal + this.subjectTotal + this.collectionTotal + this.reportTotal + this.adjustTotal;
        return total;
      },
      //scheduleTotal：待办规划    listTotal：待办清单      reviewTotal：待办审批
      //opinionTotal：意见反馈     subjectTotal：课题征集   collectionTotal：材料收集
      //opinionTagertTotal：规划衔接 endSubjectTotal:结题申请 reportTotal:监测评估
      //adjustTotal:修订调整
      goTo(path, query) {
        this.$router.push({
          path: path,
          query: query
        });
      },
      searchTo() {
        sessionStorage.setItem('detailClick', 'false');
        this.$router.push({
          path: "/searchTo",
          query: {
            keyword: this.searchInput
          }
        });
      },
      //获取当前时间
      dealWithTime() {
        var data = new Date();
        let formatDateTime;
        let Y = data.getFullYear();
        let M = data.getMonth() + 1;
        let D = data.getDate();
        let W = data.getDay();
        var week = "日一二三四五六".charAt(W);
        formatDateTime = Y + "年" + M + "月" + D + "日 " + " 星期" + week;
        return formatDateTime;
      },
      // 热词搜索
      hotSearch(keyWord) {
        var self = this;
        resultHotWord({keyword: keyWord}).then(response => {
          $(this.$refs.searchInput).autocomplete({
            source: response.data.data,
            select: function (event, ui) {
              self.setSearchInput(ui.item.value)
            },
          });
        })
      },
      setSearchInput(val) {
        this.searchInput = val
      },
      regAdd() {
        this.$router.push({
          path: "/applyFor", query: {
            chooseFlag: 'A'
          }
        });
      },
      handleAdd() {
        //   this.$router.$avueRouter.group = item.group;
        if (this.roles.indexOf(8) > -1) {
          this.fgwJudgeView = true;
          this.dialogWidthParam = '1000px'
        } else {
          this.fgwJudgeView = false;
          this.dialogWidthParam = '800px'
        }
        this.dialogVisible = true;
      },
      changeChoose(index) {

        this.chooseFlag = index;
      },
      cancel() {
        this.dialogVisible = false;
      },
      next() {
        this.$router.push({
          path: "/applyFor", query: {
            chooseFlag: this.chooseFlag
          }
        });
      },
      // 获取待办规划数量
      getScheduleList() {
        projectList(Object.assign({
          current: 1,
          size: 0,
        })).then(response => {
          this.scheduleTotal = response.data.data.total
        })
      },
      getTaskList() {
        listTask(Object.assign({
          current: 1,
          size: 0
        })).then(response => {
          this.listTotal = response.data.data.total
        })
      },
      // 获取会商反馈List
      getTopicList() {
        getTopicPage({
          current: 1,
          size: 0,
          admins: 1,
          userIds: this.userInfo.userId,
          state: '1'
        }).then(response => {
          this.topicTotal = response.data.data.total
        })
      },
      // 获取审批List
      getReviewList() {
        toDoReviewList({
          current: 1,
          size: 0,
          reviewStateNe: '11'
        }).then(response => {
          this.reviewTotal = response.data.data.total
        })
      },
      getToDoList() {
        toDoTargetOpinion(Object.assign({
          current: 1,
          size: 10,
          types: '1,2,3,5,7,8',
          states: '0,1,2',
          descs: 'create_time'
        })).then(response => {
          this.opinionTotal = response.data.data.total
        })
      },
      getResultList() {
        toDoTargetOpinion(Object.assign({
          current: 1,
          size: 10,
          types: '4',
          states: '0,1,2',
          descs: 'create_time'
        })).then(response => {
          this.subjectTotal = response.data.data.total;
        })
      },
      getmaterialCollectionSingle() {
        getTodoList(Object.assign({
          current: 1,
          size: 10,
          isEnd: false,
        })).then(response => {
          this.collectionTotal = response.data.data.total;
        })
      },
      getUnreadTotal() {
        getunreadMsg(Object.assign({
          current: 1,
          size: 1,
          haveRead: false,
        })).then(response => {
          if (response.data.code == '0') {
            this.unreadMsgTotal = response.data.data.total;
          }
        })
      },
      getopinionTagertList() {
        toDoTargetOpinion(Object.assign({
          current: 1,
          size: 10,
          type: '6',
          states: '0,1,2'
        })).then(response => {
          this.opinionTagertTotal = response.data.data.total;
        })
      },
      decomposeDraftProgressTree() {
        decomposeDraftProgressTree().then(response => {
          if (response.data.code == 0) {
            let records = response.data.data.records;
            this.workitemTotal = response.data.data.total;
          }
        })
      },

      getendSubjectTotal() {
        getEndSubjectList(Object.assign({
          current: 1,
          size: 10,
          states: '0',
        })).then(response => {
          this.endSubjectTotal = response.data.data.total;
        })
      },
      getReportTotalTotal() {
        toDoReportList(Object.assign({
          current: 1,
          size: 10,
        })).then(response => {
          this.reportTotal = response.data.data.total;
        })
      },
      getAdjustTotal() {
        taskTodo(Object.assign({
          current: 1,
          size: 10,
        })).then(response => {
          this.adjustTotal = response.data.data.total;
        })
      },

    },
    components: {
      messageScroll
    }
  };
</script>

<style lang="stylus">
.v-wel
  .el-collapse
    border none
    border-radius 10px
    overflow hidden
    // padding 20px 0
    background-color rgba(#fff,.8) 

  .el-collapse-item__header
    background-color rgba(#fff,0)
    border none 
    justify-content: space-between
    font-size 24px
    height auto
    line-height 60px
    padding 5px 30px
    padding-right 60px
    position relative
    i
      position absolute
      right 60px
      top 25px
  .el-collapse-item
    &:last-child
      // .el-collapse-item__header
      // padding-bottom  30px
  .el-collapse-item__wrap
    background-color rgba(#fff,.8)
    padding 20px 30px
    padding-right 60px
</style>